import java.util.Arrays;
import java.util.Random;

public class Test {

    public static void orderedNum(int[] array){
        for (int i = 0; i < array.length; i++) {
            array[i] = i;
        }
    }

    public static void reverseOrderedNum(int[] array){
        for (int i = 0; i < array.length; i++) {
            array[i] = array.length - i;
        }
    }

    public static void norOrderedNum(int[] array){
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(10_0000);
        }
    }

    public static void testInsertSort(int[] array){
        int[] tmpArray = Arrays.copyOf(array, array.length);
        Long start = System.currentTimeMillis();
        Sort.InsertSort(tmpArray);
        Long end = System.currentTimeMillis();
        System.out.println("插入排序耗时："+(end - start));
    }

    public static void testShellSort(int[] array){
        int[] tmpArray = Arrays.copyOf(array, array.length);
        Long start = System.currentTimeMillis();
        Sort.shellSort(array);
        Long end = System.currentTimeMillis();
        System.out.println("希尔排序耗时："+(end - start));
    }

    public static void testHeapSort(int[] array){
        int[] tmpArray = Arrays.copyOf(array, array.length);
        Long start = System.currentTimeMillis();
        Sort.heapSort(array);
        Long end = System.currentTimeMillis();
        System.out.println("堆排序耗时："+(end - start));
    }

    public static void testQuickSort(int[] array){
        int[] tmpArray = Arrays.copyOf(array, array.length);
        Long start = System.currentTimeMillis();
        Sort.quickSort(array);
        Long end = System.currentTimeMillis();
        System.out.println("快速排序耗时："+(end - start));
    }

    public static void testMergeSort(int[] array){
        int[] tmpArray = Arrays.copyOf(array, array.length);
        Long start = System.currentTimeMillis();
        Sort.mergeSort(array);
        Long end = System.currentTimeMillis();
        System.out.println("归并排序耗时："+(end - start));
    }


    public static void main(String[] args) {

        int[] array = {1, 0, 2, 9, 4, 5, 3, 8, 6, 7};
        int[] nums = {5,1,1,2,0,0};
//        Sort.InsertSort(array);
//        Sort.ShellSort(array);
//        Sort.selectSort(array);
//        Sort.selectSort2(array);
//        Sort.heapSort(array);
//        Sort.quickSort(array);
//        Sort.quickSortNor(array);
//        Sort.mergeSort(array);
        Sort.mergeSortNor(nums);
//        Sort.mergeSortNor(array);
        Sort.countSort(array);
        System.out.println(Arrays.toString(nums));
        System.out.println(Arrays.toString(array));

    }


    public static void main1(String[] args) {
        int[] array = new int[10_0000];
//        System.out.println("数组有序：");
//        orderedNum(array);
        //testInsertSort(array);
        //testShellSort(array);
       //testHeapSort(array);
//        testQuickSort(array);
//        System.out.println("数组逆序：");
//        reverseOrderedNum(array);
        //testInsertSort(array);
        //testShellSort(array);
        //testHeapSort(array);
//        testQuickSort(array);
        System.out.println("数组乱序：");
        norOrderedNum(array);
//        testInsertSort(array);
        testShellSort(array);
        testHeapSort(array);
        testQuickSort(array);
        testMergeSort(array);
    }

}
